package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallOrderReportMapper;
import org.linlinjava.litemall.db.domain.LitemallOrderReport;
import org.linlinjava.litemall.db.domain.LitemallOrderReportExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class LitemallOrderReportService {
    @Resource
    private LitemallOrderReportMapper dao;

    public void insert(LitemallOrderReport report) {
        report.setCreateTime(LocalDateTime.now());
        report.setUpdateTime(LocalDateTime.now());
        dao.insertSelective(report);
    }

    public void insert(String path, String type , Integer orderId, String fileName, String md5) {
        LitemallOrderReport report = new LitemallOrderReport();
        report.setPath(path);
        report.setType(type);
        report.setOrderId(orderId);
        report.setName(fileName);
        report.setMd5(md5);
        insert(report);
    }

    public List<LitemallOrderReport> queryByOid(Integer id) {
        LitemallOrderReportExample example = new LitemallOrderReportExample();
        example.or().andOrderIdEqualTo(id);
        return dao.selectByExample(example);
    }

     public LitemallOrderReport findByName(String path) {
        LitemallOrderReportExample example = new LitemallOrderReportExample();
        example.or().andPathEqualTo(path);
        return dao.selectOneByExample(example);
     }

    public LitemallOrderReport selectByMd5(String md5) {
        LitemallOrderReportExample example = new LitemallOrderReportExample();
        example.or().andMd5EqualTo(md5);
        return dao.selectOneByExample(example);
    }
}
